//
//  ViewDrawBoard.m
//  核心动画
//
//  Created by chichaojituan521 on 2017/5/31.
//  Copyright © 2017年 linch. All rights reserved.
//

#import "ViewDrawBoard.h"
#import "DrawLine.h"
@implementation ViewDrawBoard

-(NSMutableArray *)arrayLines
{
    if (!_arrayLines) {
        _arrayLines = [[NSMutableArray alloc]init];
    }
    return _arrayLines;
}
-(NSMutableArray *)arrayPoints
{
    if (!_arrayPoints) {
        _arrayPoints = [[NSMutableArray alloc]init];
    }
    return _arrayPoints;
}
- (void)drawRect:(CGRect)rect {
    // Drawing code
    CGContextRef context=UIGraphicsGetCurrentContext();
    
    [_arrayLines enumerateObjectsUsingBlock:^(DrawLine * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        //设置线颜色
        CGContextSetStrokeColorWithColor(context, obj.lineColor.CGColor);
        //线宽
        CGContextSetLineWidth(context, obj.lineWidth);
        //将每条线里面的点连起来
        [obj.points enumerateObjectsUsingBlock:^(NSValue  *_Nonnull pointtt, NSUInteger idx, BOOL * _Nonnull stop) {
            
            CGPoint point=pointtt.CGPointValue;
            
            if (idx==0) {
                //将画笔移动到起点
                CGContextMoveToPoint(context, point.x, point.y);
            }
            else
            {
                CGContextAddLineToPoint(context, point.x, point.y);
            }
        }];
        //所有点添加完成后  开始画
        CGContextStrokePath(context);
    }];
    
}

@end
